console.log("renderer");

for (let index = 0; index < 5; index++) {
  console.log(index);
}

window.addEventListener("DOMContentLoaded", () => {
  window.electronAPI.getVersions((value) => {
    console.log("renderer 接收到的参数", value);
  });
});

window.electronAPI.menuEvent((value) => {
  console.log("menuEvent", value);
  //  document.querySelector("h1").innerHTML = value;
});

//选择文件
window.addEventListener("DOMContentLoaded", () => {
  const btn = document.querySelector("#selectBtn");
  const container = document.querySelector("#container");
  btn.addEventListener("click", async () => {
    const files = await window.electronAPI.selectFilePreload();
    for (const file of files) {
      const input = document.createElement("input");
      input.value = file;
      container.appendChild(input);
    }
  });

  // 保存文件
  const saveBtn = document.querySelector("#saveBtn");
  saveBtn.addEventListener("click", async () => {
    const textarea = document.querySelector('[name="content"]');
    window.electronAPI.saveToFile(textarea.value);
  });
});
